Virtual attributes
What they are and how to use virtual attributes
- Virtual attributes are a way to use methods (
get
andset
) as attributes through a precompiler.
⚠️ Remember that a script with many virtual attributes can cause a longer compilation time, since there is a precompiler that interprets and tranforms your "attribute" into the original method before compiling your script ⚠️
With virtual attributes:
Example
- Note that the number of characters has decreased considerably.
public class YourClass extends Component {
public int value = 10; // select from properties
public void repeat() {
myObject.position.x = value;
myObject.position.y = value;
myObject.position.z = value;
}
}
Without virtual attributes:
Example
- Note that the number of characters has increased considerably.
public class YourClass extends Component {
public int value = 10; // select from properties
public void repeat() {
myObject.getPosition().setX(value);
myObject.getPosition().setY(value);
myObject.getPosition().setZ(value);
}
}
You can also use virtual attributes in vectors
Example
- Note that in the
repeat
function it is not necessary to call the methods of the operations.
public class YourClass extends Component {
private Vector3 vector1 = new Vector3(1, 1, 1);
private Vector3 vector2 = new Vector3(2, 2, 2);
public void start() {
// assigning values with virtual attributes
vector1.x = 1; // the same as vector1.setX(1);
vector1.y = 1; // the same as vector1.setY(1);
vector1.z = 1; // the same as vector1.setZ(1);
}
public void repeat() {
// the same as vector1 = vector1.sumLocal(vector2);
vector1 += vector2;
// the same as vector1 = vector1.subLocal(vector2);
vector1 -= vector2;
// the same as vector1 = vector1.mulLocal(vector2);
vector1 *= vector2;
// the same as vector1 = vector1.divLocal(vector2);
vector1 /= vector2;
}
}
⚠️ If the use of virtual attributes presents some kind of error just use the methods normally ⚠️